/*
 * File Name:               UIViewCell.cs
 *
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>
 * Create Date:             2016/11/24
 */

using UnityEngine;

public class UIListView<TView> : UIListCell where TView : UIView, new()
{
    private TView mView;
    private UIWindow mWindow;
    
    public void setWindow(UIWindow window)
    {
        mWindow = window;
    }

    protected override void onDisplay(UIContext context, object args)
    {
        mView = XCachePool.Singleton.pop<TView>();
        mView.onCreated(context, mWindow, args);
    }

    protected override void onHide()
    {
        XCachePool.Singleton.push(mView);
        mView = null;
    }

    public override void clear()
    {
        if (mView != null)
        {
            XCachePool.Singleton.push(mView);
            mView = null;
        }

        base.clear();
    }

    public static UIListView<TView> create(GameObject prefab, object args)
    {
        var ret = new UIListView<TView>();
        ret.setPrefab(prefab);
        ret.setDatas(args);

        return ret;
    }

    public TView getView()
    {
        return mView;
    }
}